package com.hotel.interceptor;

import com.hotel.util.Constant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.annotation.HandlesTypes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取Session中的用户信息
        Object user=request.getSession().getAttribute(Constant.LOGIN_USER);
        if(user==null){
            //从新定向登录页面
            response.sendRedirect("/");
            return false;
        }else{
            //已登录，放行
            return true;
        }
    }
}
